package com.itheima.controller;

import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController("backendOrderCheckItemController")
@Slf4j
@RequestMapping("/checkitem")
public class CheckItemController {
    @Autowired
    CheckItemService checkItemService;
    //新增检查项-----
    @PostMapping("/add")
    Result additem(@RequestBody CheckItem checkItem ){
        log.info("新增检查项：{}", checkItem);
        checkItemService.additem(checkItem);
        return  new Result(true,"新增项目检查成功",null);
    }
    //删除检查项-----
    @GetMapping("/delete")
    Result deleteById( Long id){
        log.info("根据id删除检查项：{}", id);
        checkItemService.deleteById(id);
        return new Result(true,"删除检查项成功",null);
    }
    //根据检查组id查询检查项------
    @GetMapping("/findCheckItemIdsByCheckGroupId")
    Result getByGroupId(int checkgroupId){
        log.info("根据检查组id查询检查项：{}",checkgroupId);
        ArrayList<Integer>resultList=checkItemService.getByGroupId(checkgroupId);
        return new Result(true,"查询检查项成功",resultList);
    }
    //编辑检查项------
    @PostMapping("/edit")
    Result updateByItemId(@RequestBody CheckItem checkItem){
        log.info("编辑检查项：{}", checkItem);
        checkItemService.updateByItemId(checkItem);
        return new Result(true,"编辑检查项成功",null);
    }
    //分页查询-------------
    @PostMapping("/findPage")
    PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        log.info("分页查询检查项：{}", queryPageBean);
        return checkItemService.findPage(queryPageBean);
    }
    //查询所有检查项-----------
    @GetMapping("findAll")
    Result findAll(){
        log.info("查询所有检查项");
        ArrayList<CheckItem>resultList=checkItemService.findAll();
        return new Result(true,"查询检查项成功",resultList);

    }
    //根据id查询检查项--------
    @GetMapping ("findById")
    Result findById(int id){
        log.info("根据id查询检查项：{}", id);
        CheckItem checkItem=checkItemService.findById(id);
        return new Result(true,"查询检查项成功",checkItem);
    }
}
